package org.streets.commons.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Misc utils for common application used
 *
 * @author Zenberg.D
 *
 */
public final class ResolveUtils {

    public static String resolveUrlHost(String url) {
		if (url == null || url.length()==0) return "";
		String site = "";
		Pattern pattern = Pattern.compile("(http://)(\\S*?[^/])(/)");
		Matcher matcher = pattern.matcher(url);
		if (matcher.find())
		{
			site = matcher.group(2);
			int tmpPos = site.indexOf(':');
			if (tmpPos > 0)
				site = site.substring(0, tmpPos);
		}
		return site;
	}

    public static String resolveDateStr(String text) {
		String ret = null;
		Pattern p = Pattern.compile("((\\d{2}|\\d{4})[年\\\\/-])*\\s{0,1}\\d{1,2}[月\\\\/-]\\s{0,1}\\d{1,2}(日|\\\\*|-*|/*)");
		Matcher m = p.matcher(text);
		if(m.find())
		{
			ret = m.group();
		}
		return ret;
	}

}
